package com.villaday.idf.custom;


import android.app.Activity;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;

import luojie.hnulab.librarydemo.picker.DatePicker;

/**
 * Created by admin on 2018/9/8.
 */

public class CustomHeaderAndFooterPicker extends DatePicker implements DatePicker.OnWheelListener {

    private int status = -1;


    public CustomHeaderAndFooterPicker(Activity activity) {
        super(activity);
    }


    public CustomHeaderAndFooterPicker(Activity activity, @DateMode int mode) {
        super(activity, mode);
        //设置label颜色（灰）  选中颜色 （黑） 未选中颜色（灰）
        setLabelTextColor(0xFF999999, 0xFF333333, 0xFF999999);
        //设置边线颜色（灰）
        setDividerColor(0xFF999999);
        //关闭顶部栏
        setTopLineVisible(false);
    }


    public CustomHeaderAndFooterPicker(Activity activity, @DateMode int mode, int status) {
        super(activity, mode);
        //设置label颜色（灰）  选中颜色 （黑） 未选中颜色（灰）
        setLabelTextColor(0xFF999999, 0xFF333333, 0xFF999999);
        //设置边线颜色（灰）
        setDividerColor(0xFF999999);
        //关闭顶部栏
        setTopLineVisible(false);

        this.status = status;
    }


    @Nullable
    @Override
    protected View makeHeaderView() {
        View view = LayoutInflater.from(activity).inflate(R.layout.picker_header, null);
        TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
        TextView submitView = (TextView) view.findViewById(R.id.picker_submit);
        TextView cancelView = (TextView) view.findViewById(R.id.picker_cancel);
        switch (status) {
            case 1:
                tvTitle.setText("请选择开始时间");
                tvTitle.setVisibility(View.VISIBLE);
                break;

            case 2:
                tvTitle.setText("请选择结束时间");
                tvTitle.setVisibility(View.VISIBLE);
                break;
            default:
                tvTitle.setVisibility(View.INVISIBLE);
                break;
        }
        submitView.setText(submitText);
        cancelView.setText(cancelText);
        cancelView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener != null)
                    mListener.ReverseDateTime();
                dismiss();
            }
        });
        submitView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                onSubmit();
            }
        });
        return view;
    }

    @Nullable
    @Override
    protected View makeFooterView() {
        View view = LayoutInflater.from(activity).inflate(R.layout.picker_footer, null);
        return view;
    }


    @Override
    public void onSubmit() {
        super.onSubmit();
    }


    @Override
    public void onYearWheeled(int index, String year) {

    }

    @Override
    public void onMonthWheeled(int index, String month) {

    }

    @Override
    public void onDayWheeled(int index, String day) {

    }


    /**
     * 用于点击对话框取消按钮还原选择的时间
     */
    public interface OnCancelDateTimeListiner {
        public void ReverseDateTime();
    }

    public OnCancelDateTimeListiner mListener;


    public void setOnCancelDateTimeListener(OnCancelDateTimeListiner listener) {
        this.mListener = listener;
    }
}

